package BLCTest

import (
	"bytes"
	"encoding/gob"
	"log"
)

type Block struct{
	A string
	C int
}

func NewBlock(a string,c int)*Block{
	return &Block{a,c}
}


//将block对象序列化成[]byte,非常方便
func (b *Block)EncodeBlock()[]byte{
	var buff bytes.Buffer

	encoder:=gob.NewEncoder(&buff)
	err:=encoder.Encode(b)

	if err!=nil{
		log.Panic(err)
	}

	return buff.Bytes()
}

//将[]byte序列化成block对象,非常方便
func DecodeBlock(d []byte)*Block{
	var block Block

	decode:=gob.NewDecoder(bytes.NewReader(d))
	err:=decode.Decode(&block)

	if err!=nil{
		log.Panic(err)
	}

	return &block
}
